package cn.sczc.jh.client.controller.team;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.sczc.jh.client.base.AbstractController;
import cn.sczc.jh.client.entity.Teams;
import cn.sczc.jh.client.service.team.TeamService;
import cn.sczc.jh.client.vo.MapVo;

@RestController
@RequestMapping("/teams")
public class TeamController extends AbstractController {

	@Autowired
	private TeamService teamService;

	@RequestMapping(value = "", method = RequestMethod.GET)
	public ResponseEntity<ModelMap> list(ModelMap modelMap, @RequestParam Map<String, Object> params) {
		@SuppressWarnings("unchecked")
		Page<Teams> page = (Page<Teams>) super.getPage(params);
		Page<Teams> data = teamService.queryTeams(page, params);
		return setSuccessModelMap(modelMap, data);
	}

	@RequestMapping(value = "", method = RequestMethod.POST)
	public ResponseEntity<ModelMap> save(ModelMap modelMap, @RequestBody Teams team) {
		int count = teamService.insert(team);
		return setSuccessModelMap(modelMap, count);
	}

	@RequestMapping(value = "", method = RequestMethod.PUT)
	public ResponseEntity<ModelMap> update(ModelMap modelMap, @RequestBody Teams team) {
		int count = teamService.update(team);
		return setSuccessModelMap(modelMap, count);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public ResponseEntity<ModelMap> delById(ModelMap modelMap, @PathVariable String id) {
		int count = teamService.delById(id);
		return setSuccessModelMap(modelMap, count);
	}

	/**
	 * 获取聚合数据
	 * 
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "/cluster", method = RequestMethod.GET)
	public ResponseEntity<ModelMap> clusterList(ModelMap modelMap, @RequestParam Map<String, Object> params) {
		MapVo data = teamService.qryClusterList(params);
		return setSuccessModelMap(modelMap, data);
	}

}
